#ifndef GPU_TIMER_H
#define GPU_TIMER_H

#include <cuda_runtime.h>
#include <iostream>

class GPUTimer {
public:
    GPUTimer() {
        cudaEventCreate(&start_);
        cudaEventCreate(&stop_);
    }

    ~GPUTimer() {
        cudaEventDestroy(start_);
        cudaEventDestroy(stop_);
    }

    void start() {
        cudaEventRecord(start_, 0);
    }

    float stop() {
        cudaEventRecord(stop_, 0);
        cudaEventSynchronize(stop_);
        float ms = 0;
        cudaEventElapsedTime(&ms, start_, stop_);
        return ms;
    }

private:
    cudaEvent_t start_, stop_;
};

#endif // GPU_TIMER_H
